package utils;
/*
@ClassName:     DB
@Author:        YangXu
@Need:          
@Date:          2022/4/27
@Time:          2022-04-27 9:36
*/

//


import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.*;

public class DB {
    private static DataSource ds;
    static{
        ds = new ComboPooledDataSource();
    }
    public Connection getConnection() throws SQLException{

       return ds.getConnection();

    }
    public void close(Connection connection, Statement statement, ResultSet resultSet) throws SQLException {
        if (connection != null) {
            connection.close();
        }
        if (resultSet != null) {
            resultSet.close();
        }
        if (statement != null) {
            statement.close();
        }
    }

    public void close(Connection connection, PreparedStatement ps, ResultSet resultSet) throws SQLException {
        if (connection != null) {
            connection.close();
        }
        if (resultSet != null) {
            resultSet.close();
        }
        if (ps != null) {
            ps.close();
        }
    }

    public static void main(String[] args) {
        DB db = new DB();
        try {
            Connection connection = db.getConnection();
            System.out.println(connection);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
/*

 */